Method 1(Data Type) (minimum value + math. Random () * (maximum value-Minimum value + 1 ))Example:(INT) (1 + math. Random () * (10-1 + 1 ))INT-type numbers from 1 to 10Method 2Obtain Random NumberFor (INT I = 0; I {System. Out. println (INT) (1 +
This paper mainly introduces 3 kinds of methods of obtaining random number in Java, mainly using random () function to realize
Method 1
(data type) (Minimum +math.random () * (maximum-min +1)) Example:
(int) (1+math.random () * (10-1+1))
There is no real random number generator in the computer, but it can make the resulting digital repetition rate very low, so it looks like a real random number, the program to achieve this function is called pseudo-random number generator.There are
There is no real random number generator in the computer, but it can make the generated digital repetition rate very low, it seems like a real random number, to achieve this function
ProgramIt is called a pseudo-random number generator.
There are
Today, a small program of genetic algorithm is compiled. In the default constructor of an individual class, the initialization of binary encoding is done using random numbers. The random number in C + + is actually pseudo-random number, that is, the
Sourcehttps://blogs.unity3d.com/cn/2015/01/07/a-primer-on-repeatable-random-numbers/(English version)Http://www.manew.com/thread-37144-1-1.htmlNo matter what kind of program you create, you can almost do without random numbers. If you want to
The random class is used in Java for the resulting stochastic number, new Random (10): 10 is the number of seeds. Note: One of the characteristics of random is that random objects of the same seed number are exactly the same as those generated by
The standard library (included in ) provides two functions to help generate pseudo-random numbers:
Function 1: int rand (void );Returns a random integer between [seed, rand_max (0x7fff) starting from the seed specified in srand (SEED.
pseudo-Random (preundorandom): Random numbers generated by the algorithm are pseudo-random!! only random numbers generated by real random events are really random!! For example, random numbers are generated through the machine's hardware noise,
Copyright:Original works. If you need to reprint them, please contact the author. Otherwise, legal liability will be held.
Java random number SummaryRandom numbers are widely used in practice. For example, a fixed-length string or number
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.